//
//  HDCFNavController.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/10/28.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFNavController.h"
#import "UIBarButtonItem+Extension.h"

@interface HDCFNavController ()

@end

@implementation HDCFNavController

- (void)viewDidLoad{
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = [UIColor whiteColor];
}
//设置导航条的颜色
+ (void)initialize{
    if (self == [HDCFNavController class]) {
        NSArray *array = [[NSArray alloc] initWithObjects:[HDCFNavController class], nil];
        UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:array];
        [bar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
        NSDictionary *dict = @{
                               NSForegroundColorAttributeName : [UIColor whiteColor],
                               NSFontAttributeName : [UIFont systemFontOfSize:20]
                               };
        [bar setTitleTextAttributes:dict];
        [bar setTintColor:[UIColor whiteColor]];
    }
    
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(back) imageN:[UIImage imageNamed:@"icon_back"] highImageN:[UIImage imageNamed:@"icon_back"]];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back{
    [self popViewControllerAnimated:YES];
}

@end
